<!DOCTYPE html>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>aqoeous-sample</title>
    <meta name="keywords" content="aqoeous-sample">
    <meta name="description" content="aqoeous-sample">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <link th:href="@{favicon.ico}" rel="stylesheet"/>
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>
    <link th:href="@{/snow/css/snow-ui.css?v=2.4.0}" rel="stylesheet"/>
    <style type="text/css">
        .nav > li:hover .dropdown-menu {display: block;}
    </style>
    <!-- 全局js -->
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/js/plugins/metisMenu/jquery.metisMenu.js}"></script>
    <script th:src="@{/js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>
    <script th:src="@{/ajax/libs/blockUI/jquery.blockUI.js}"></script>
    <script src="http://tajs.qq.com/stats?sId=62048022"></script>
    <script th:src="@{/snow/js/snow-ui.js?v=2.4.0}"></script>
    <script th:src="@{/snow/index.js}"></script>
    <script th:src="@{/ajax/libs/fullscreen/jquery.fullscreen.js}"></script>
</head>
<!--<body class="fixed-sidebar full-height-layout " style="overflow: hidden" >-->
<body class="fixed-sidebar full-height-layout" >
<div >
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-3">
                <div class="signin-info">
                    <label  class="form-inline control-label" th:text="${tokenUser?.userName}"></label>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-4">
                <h2>联合查询</h2>
                <p>
                    <label class="form-inline control-label">shop位于数据库aqoeous_db1,item位于数据库aqoeous_db2</label>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopItemList(1,10)">店铺及旗下商品</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopItemList2(1,10,[1,2])">店铺及旗下商品,高效查询[数据需客户端处理]</button>
                </p>
                <p>
                    <label class="form-inline control-label">这里展示的是shopId为1和2的数据,查询语法为并列关系,先查询的shopQO,再根据shopQO中的返回值查询itemQO[对数据库只查询2次]</label>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopItemList(1,10,undefined,undefined,-1)">店铺及旗下商品总数</button>
                </p>
                <p>
                <label class="form-inline control-label">子级item中的pageSize设置为-1即可,其中的total就是item总数</label>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemShopList(1,10)">商品主表,同时需要查出所属店铺名称</button>
                </p>
                <p>
                    <label class="form-inline control-label">可以看出,很多商品是同一个店铺的,这种情况下使用高效查询数据量会少很多</label>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemShopList2(1,10)">商品主表[高效查询]</button>
                </p>
                <p>
                    <label class="form-inline control-label">之前方式的查询是item中有几条数据,就查了几次shop表中的数据.而高效查询是先根据返回值中itemQO的shopId,然后作为shopIdList参数去查shopQO得到最终的数据集</label>
                </p>

                <h2>分页</h2>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopList(1,1)">shopList-第1页</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopList(2,1)">shopList-第2页</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemList(1,3)">itemList-第1页</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemList(2,3)">itemList-第2页</button>
                </p>
                <h2>筛选</h2>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopList(1,10,[2])">shopList-根据主键筛选</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="shopList(1,10,undefined,['茶','蛋'])">shopList-名称筛选</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemList(1,10,[1])">itemList-根据店铺筛选1</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemList(1,10,[2])">itemList-根据店铺筛选2</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="itemList(1,10,undefined,['蛋'])">itemList-名称筛选</button>
                </p>
                <h2>合并到父级</h2>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="mergeParent1(1,10)">mergeParent-aqoeousChild中的放到父结果中</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="mergeParent2(1,10)">mergeParent-aqoeousChild中的list放到父结果中</button>
                </p>
                <p>
                    <button type="button" class="btn btn-primary btn-lg " onclick="mergeParent3(1,10)">mergeParent-aqoeousChild中的list第一个结果放到父结果中</button>
                </p>
                <h2>语句后端提供</h2>
                <p>
                    <a href="/aqoeous/shop/list?pageSize=1&pageNum=1" class="btn btn-primary btn-lg" target="_blank" role="button">shopList</a>
                </p>
                <p>
                    <a href="/aqoeous/item/list?pageSize=3&pageNum=1&nameList=腐,臭" class="btn btn-primary btn-lg" target="_blank" role="button">itemList</a>
                </p>
            </div>
            <div class="col-sm-8">
                <h2>发送
                <button type="button" class="btn btn-primary btn-lg" onclick="send()">发送调试</button>
                    </h2>
                <textarea id="aqoeous" class="form-control" rows="15" name="text" ></textarea>
                <h2>返回</h2>
                <textarea id="msg" class="form-control" rows="40" name="text" ></textarea>
            </div>
        </div>
    </div>
</div>
<script >

    function itemShopList(pageNum,pageSize,shopIdList,nameList) {
        var json=[
            {
                "resultName": "itemQO",
                "qoName": "itemQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                },
                "qoChilds": [{
                    "resultName": "shop",
                    "mergeParent": true,
                    "listFirstMergeParent": true,
                    "qoName": "shopQO",
                    "qoJson": {
                        "pageNum": 1,
                        "pageSize": 1
                    },
                    "relationships": [
                        {
                            "paramName": "shopIdList",
                            "sourceDatas": [
                                "shopId"
                            ]
                        }
                    ]

                }]
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }

    function itemShopList2(pageNum,pageSize,shopIdList,nameList,itemPageSize) {
        var json=[
            {
                "resultName": "itemQO",
                "qoName": "itemQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                }
            },
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                },
                "relationships":[
                    {
                        "paramName":"shopIdList",
                        "sourceDatas": [
                            "itemQO.shopId"
                        ]
                    }
                ]

            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }

    function shopItemList2(pageNum,pageSize,shopIdList,nameList,itemPageSize) {
        var json=[
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                }
            },
            {
                "resultName": "itemQO",
                "qoName": "itemQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                },
                "relationships":[
                    {
                        "paramName":"shopIdList",
                        "sourceDatas": [
                            "shopQO.shopId"
                        ]
                    }
                ]

            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }

    function shopItemList(pageNum,pageSize,shopIdList,nameList,itemPageSize) {
        var json=[
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                },
                "qoChilds": [{
                    "resultName": "itemList",
                    "mergeParent": true,
                    "listMergeParent":true,
                    "qoName": "itemQO",
                    "qoJson": {
                        "pageNum": 1,
                        "pageSize": itemPageSize!=undefined?itemPageSize:10
                    },
                    "relationships": [
                        {
                            "paramName": "shopIdList",
                            "sourceDatas": [
                                "shopId"
                            ]
                        }
                    ]

                }]
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }

    function mergeParent1(pageNum,pageSize) {
        var json=[
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                },
                "qoChilds": [{
                    "mergeParent" : true,
                    "listFirstMergeParent" : false,
                    "listMergeParent" : false,
                    "resultName": "virtualItemList",
                    "qoName": "itemQO",
                    "qoJson": {
                        "pageNum": 1,
                        "pageSize": 999999
                    },
                    "relationships": [
                        {
                            "paramName": "shopIdList",
                            "sourceDatas": [
                                "shopId"
                            ]
                        }
                    ]

                }]
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }

    function mergeParent2(pageNum,pageSize) {
        var json=[
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                },
                "qoChilds": [{
                    "mergeParent" : true,
                    "listFirstMergeParent" : false,
                    "listMergeParent" : true,
                    "resultName": "virtualItemList",
                    "qoName": "itemQO",
                    "qoJson": {
                        "pageNum": 1,
                        "pageSize": 999999
                    },
                    "relationships": [
                        {
                            "paramName": "shopIdList",
                            "sourceDatas": [
                                "shopId"
                            ]
                        }
                    ]

                }]
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }
    function mergeParent3(pageNum,pageSize) {
        var json=[
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                },
                "qoChilds": [{
                    "mergeParent" : true,
                    "listFirstMergeParent" : true,
                    "listMergeParent" : false,
                    "resultName": "virtualItem",
                    "qoName": "itemQO",
                    "qoJson": {
                        "pageNum": 1,
                        "pageSize": 999999
                    },
                    "relationships": [
                        {
                            "paramName": "shopIdList",
                            "sourceDatas": [
                                "shopId"
                            ]
                        }
                    ]

                }]
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }

    function itemList(pageNum,pageSize,shopIdList,nameList) {
        var json=[
            {
                "resultName": "itemQO",
                "qoName": "itemQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                }
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        //发送接口请求
        send()
    }



    function shopList(pageNum,pageSize,shopIdList,nameList) {
        var json=[
            {
                "resultName": "shopQO",
                "qoName": "shopQO",
                "qoJson": {
                    "pageNum": pageNum,
                    "pageSize": pageSize,
                    "shopIdList":shopIdList,
                    "nameList":nameList
                }
            }
        ];
        //格式化成json字符串,缩进4格
        jsonStr=JSON.stringify(json,undefined,4);
        $("#aqoeous").val(jsonStr);
        send()
    }

    function send() {
        var text = $("#aqoeous").val();
        aqoeous("/aqoeous",text);
    }

    function aqoeous(url,json) {
        $.ajax({
            type: 'POST',
            url: url,
            data: (json),
            contentType:"application/json;charset=utf-8",
            success: function (data) {
                console.log(data);
                $("#msg").text(JSON.stringify(data,undefined,4));

            },
            dataType: "json"
        });

    }
</script>
</body>
</html>
